package com.nq.service.impl;
/**
 * 开发者----股牛网络
 * 联系TG：gncms
 */
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.common.ServerResponse;
import com.nq.dao.*;
import com.nq.pojo.*;
import com.nq.pojo.vo.FundsApplyVo;
import com.nq.pojo.vo.StFundApplyDetailVo;
import com.nq.service.*;
import com.nq.utils.*;
import com.nq.utils.redis.CookieUtils;
import com.nq.utils.redis.JsonUtil;
import com.nq.utils.redis.RedisShardedPoolUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 基金交易记录
 * @author lr
 * @date 2020/07/24
 */
@Service("IStFundService")
public class StFundServiceImpl implements IStFundService {
    private static final Logger log = LoggerFactory.getLogger(StFundServiceImpl.class);

    @Resource
    private StFundApplyDetailMapper stFundApplyDetailMapper;
    @Autowired
    IAgentUserService iAgentUserService;
    @Autowired
    AgentUserMapper agentUserMapper;

    @Override
    public ServerResponse<PageInfo> getList(StFundApplyDetailVo applyDetail, Integer pageNum, Integer pageSize, HttpServletRequest request) {


        Page<StFundApplyDetail> page = PageHelper.startPage(pageNum, pageSize);

        Integer userId = applyDetail.getUserId();
        String userPhone = applyDetail.getUserPhone();
        Integer agentId = applyDetail.getAgentId();
        String orderNumber = applyDetail.getOrderNumber();
        Integer tradeType = applyDetail.getTradeType();
        String fundCode = applyDetail.getFundCode();

        List<StFundApplyDetailVo> list = stFundApplyDetailMapper.queryAdminFundApplyList(userId, userPhone, agentId, orderNumber, tradeType, fundCode);

        PageInfo pageInfo = new PageInfo(page);
        pageInfo.setList(list);
        return ServerResponse.createBySuccess(pageInfo);
    }

    @Override
    public ServerResponse getAgentList(StFundApplyDetailVo applyDetail, int pageNum, int pageSize, HttpServletRequest request) {
        AgentUser currentAgent = this.iAgentUserService.getCurrentAgent(request);

        Page<StFundApplyDetail> page = PageHelper.startPage(pageNum, pageSize);

        Integer agentId = currentAgent.getId();
        Integer userId = applyDetail.getUserId();
        String userPhone = applyDetail.getUserPhone();
        String orderNumber = applyDetail.getOrderNumber();
        Integer tradeType = applyDetail.getTradeType();
        String fundCode = applyDetail.getFundCode();

        List<StFundApplyDetailVo> list = stFundApplyDetailMapper.queryAdminFundApplyList(userId, userPhone, agentId, orderNumber, tradeType, fundCode);

        PageInfo pageInfo = new PageInfo(page);
        pageInfo.setList(list);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
